//
//  MVDetailViewController.m
//  海角音乐
//
//  Created by dllo on 15/8/17.
//  Copyright (c) 2015年 杨元石. All rights reserved.
//

#import "MVDetailViewController.h"


@interface MVDetailViewController ()

@end


@implementation MVDetailViewController

- (void)dealloc
{
    [_videoController release];
    [_mvModel release];
    [super dealloc];
}

- (void)viewDidLoad {
    
    [super viewDidLoad];
    self.view.backgroundColor = COLOR(34, 43, 47, 1.0);
    CGFloat title_width = SCREEN_WIDTH*0.533333; // 200
    CGFloat title_height = SCREEN_WIDTH*0.08; // 30
    
    self.TitleView = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, title_width, title_height)];
    self.TitleView.textColor = [UIColor whiteColor];
    self.TitleView.font = [UIFont systemFontOfSize:14];
    self.TitleView.textAlignment = NSTextAlignmentCenter;
    self.TitleView.text = self.mvModel.desc;
    self.navigationItem.titleView = self.TitleView;
    [self playVideo];
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"fanhui_32.png"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStyleDone target:self action:@selector(LeftBack)];
    
}
// pop 回去
- (void)LeftBack
{
    self.videoController.judge = YES;
    [self.navigationController popViewControllerAnimated:YES];
   
}

// 播放模式
- (void)playVideo{
    
    NSArray *mvlistArr = self.mvModel.mvList;
    if (mvlistArr.count > 1) {
        
        NSDictionary *dic = [mvlistArr objectAtIndex:1];
        NSURL *url = [NSURL URLWithString:[dic objectForKey:@"url"]];
        [self addVideoPlayerWithURL:url];
        
    } else {        
        NSDictionary *dic = [mvlistArr objectAtIndex:0];
        NSURL *url = [NSURL URLWithString:[dic objectForKey:@"url"]];
        [self addVideoPlayerWithURL:url];
    }
}

// 播放方法
- (void)addVideoPlayerWithURL:(NSURL *)url{
    if (!self.videoController) {
        CGFloat width = [UIScreen mainScreen].bounds.size.width;
        self.videoController = [[KrVideoPlayerController alloc] initWithFrame:CGRectMake(0, SCREEN_WIDTH/1.8, width, width*(9.0/16.0))];

        [self.videoController setDimissCompleteBlock:^{
            
            self.videoController = nil;
            
        }];
        [self.videoController setWillBackOrientationPortrait:^{
            [self toolbarHidden:NO];
        }];
        [self.videoController setWillChangeToFullscreenMode:^{
            [self toolbarHidden:YES];
        }];
        [self.view addSubview:self.videoController.view];
    }
    self.videoController.contentURL = url;
    
}
//隐藏navigation tabbar 电池栏
- (void)toolbarHidden:(BOOL)Bool{
    self.navigationController.navigationBar.hidden = Bool;
    self.tabBarController.tabBar.hidden = Bool;
    [[UIApplication sharedApplication] setStatusBarHidden:Bool withAnimation:UIStatusBarAnimationFade];
}

- (void)viewWillDisappear:(BOOL)animated
{
    
    
    
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
